<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"  lang="en">
<head>
  <meta charset="UTF-8">
  <script type="text/javascript" th:src="@{/static/js/jquery-1.9.1.min.js}"></script>
  <script type="text/javascript" th:src="@{/static/layui-v2.6.13/layui/layui.js}"></script>
  <link rel="stylesheet" type="text/css" th:href="@{/static/layui-v2.6.13/layui/css/layui.css}"/>
  <title>Admin</title>
</head>
<body>
<table class="layui-table">

  <span th:if="${root eq 'root'}">
    <tr  >
    <td>id</td>
    <td>账户名</td>
    <td>密码</td>
    <td>权限</td>
      <td>操作</td>
      <td>操作</td>
  </tr>
  <tr th:each="rt:${rlist}" >
    <td th:text="${rt.id}" > </td>
    <td th:text="${rt.name}" > </td>
    <td >***</td>
    <td >超级账号</td>
    <td><button onclick="openLayer()" class="layui-btn layui-btn-sm layui-btn-primary">创建</button></td>
    <td><button class="layui-btn layui-btn-sm layui-btn-primary">#</button></td>
  </tr>
  <tr th:each="ad,adin:${list}" >
    <td th:text="${ad.id}" name="id"> </td>
    <td><input  th:value="${ad.name}" name="name"/> </td>
    <td><input  th:value="${ad.password}" name="password"/> </td>
    <td >普通账号</td>
    <td><button th:onclick="update([[${adin.index}]])" class="layui-btn layui-btn-sm layui-btn-primary">更新</button></td>
    <td><button th:onclick="deletes([[${adin.index}]])" class="layui-btn layui-btn-sm layui-btn-primary">删除</button></td>
  </tr>
  </span>
  <span th:if="${root ne 'root'}">
    <tr>
    <td>id</td>
    <td>账户名</td>
    <td>密码</td>
    <td>权限</td>
  </tr>
  <tr th:each="rt:${rlist}" >
    <td th:text="${rt.id}" > </td>
    <td th:text="${rt.name}" > </td>
    <td >***</td>
    <td >超级账号</td>
  </tr>
  <tr th:each="ad:${list}" >
    <td th:text="${ad.id}" > </td>
    <td th:text="${ad.name}" > </td>
    <td >*** </td>
    <td >普通账号</td>
  </tr>
  </span>
</table>
<script>
function update(num){
	var name = document.getElementsByName("name")[num].value;
	var pass = document.getElementsByName("password")[num].value;
	var id = document.getElementsByName("id")[num].textContent;
    $.ajax({
      url:"update",
      type:"post",
      data:"id="+id+"&name="+name+"&password="+pass,
      success:function(obj){
      window.location.reload();
      },
      error:function(){
      alert(id);
      alert(name);
      alert(pass);
      }
    });
}
function deletes(num){
  var id = document.getElementsByName("id")[num].textContent;
  $.ajax({
    url:"delete",
    type:"post",
    data:"id="+id,
    success:function(obj){
    window.location.reload();
    },
    error:function(){
    alert(id);
    }
  });
}

layui.use("layer", function(){
    var layer = layui.layer;
});

function openLayer(){
    layer.open({
      type: 2,
      area: ['650px', '500px'],
      content: 'toinsert',
      end: function(){
          location.reload();
      }
    });
}
</script>
</body>
</html>